package com.hotel.action;

import java.util.List;
import java.util.Map;

import com.hotel.constant.Method;
import com.hotel.constant.Msg;
import com.hotel.constant.Page;
import com.hotel.entity.Account;
import com.hotel.service.AccountService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class AccountAction extends ActionSupport implements CRUDAction {
	
	private AccountService accountService;
	
	/**
	 * 登录帐号
	 */
	private Account account;

	private String page;
	
	/**
	 * 登陆
	 * @return
	 */
	public String login(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		System.out.println("进入login方法");
		Account account =  accountService.login(this.account);
		if (account != null) {
			session.put("user", account);
			page = Method.GUIDE;
			return Method.METHOD;
		} else {
			page = Page.LOGIN;
			return SUCCESS;
		}
	}
	
	/**
	 * 退出登陆
	 * @return
	 */
	public String quitLogin() {
		ActionContext.getContext().getSession().remove(Msg.USER);
		page = Page.LOGIN;
		return SUCCESS;
	}
	
	@Override
	public String add() {
		return SUCCESS;
	}

	@Override
	public String delete() {
		return SUCCESS;
	}

	@Override
	public String selectForUpdate() {
		return SUCCESS;
	}

	@Override
	public String update() {
		return SUCCESS;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public String show() {
		ActionContext ac = ActionContext.getContext();
		Map<String, Object> session = ac.getSession();
		List<Account> accountList = accountService.show((Account)session.get(Msg.USER));
		((Map)ac.get("request")).put("accountList", accountList);
		page = Page.ACCOUNT_INFO;
		return SUCCESS;
	}
	
	
	/* ####################################### */
	/* ##########   getter/setter  ########### */
	/* ####################################### */
	
	public String getPage() {
		return page;
	}
	public void setAccountService(AccountService accountService) {
		this.accountService = accountService;
	}
	public Account getAccount() {
		return account;
	}
	public void setAccount(Account account) {
		this.account = account;
	}

	
	
}
